function loadTableScripts(callback, contextPath, locale, editable) {
	var scripts = [ contextPath + '/js/plugins/bootstrapTable/bootstrap-table.min.js',
			contextPath + '/js/plugins/bootstrapTable/locale/bootstrap-table-' + locale + '.min.js' ];

	if (editable) {
		scripts.push(contextPath + '/js/plugins/bootstrapTable/editable/bootstrap-table-editable.js');
		scripts.push(contextPath + '/js/plugins/x-editable/bootstrap-editable.js');
	}

	var eachSeries = function(arr, iterator, callback) {
		callback = callback || function() {
		};
		if (!arr.length) {
			return callback();
		}
		var completed = 0;
		var iterate = function() {
			iterator(arr[completed], function(err) {
				if (err) {
					callback(err);
					callback = function() {
					};
				} else {
					completed += 1;
					if (completed >= arr.length) {
						callback(null);
					} else {
						iterate();
					}
				}
			});
		};
		iterate();
	};

	eachSeries(scripts, getTableScript, callback);
}

function getTableScript(url, callback) {
	var head = document.getElementsByTagName('head')[0];
	var script = document.createElement('script');
	script.src = url;

	var done = false;
	// Attach handlers for all browsers
	script.onload = script.onreadystatechange = function() {
		if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
			done = true;
			if (callback)
				callback();

			// Handle memory leak in IE
			script.onload = script.onreadystatechange = null;
		}
	};

	head.appendChild(script);

	// We handle everything using the script element injection
	return undefined;
}

function booleanFormatter(value) {
	var icon = value == true ? 'glyphicon-ok' : 'glyphicon-remove';
	return '<i class="glyphicon ' + icon + '"></i> ';
}

function queryGenericParams(toolbar, params) {
	toolbar.find('input[name]').each(function() {
		params[$(this).attr('name')] = $(this).val();
	});
	toolbar.find('select[name]').each(function() {
		params[$(this).attr('name')] = $(this).val();
	});
	return params;
}

function detailFormatterDefault(index, row, t) {
	var options = t.bootstrapTable('getOptions');
	var colunms = options.columns[0];
	var html = [];
	for (var i = 0; i < colunms.length; i++) {
		if (colunms[i].title) {
			var field = colunms[i].field
			var rowdata = "";
			$.each(row, function(key, value) {
				if (field == key)
					rowdata = value;
			});
			html.push('<p><b>' + colunms[i].title + ':</b> ' + rowdata + '</p>');
		}
	}
	return html.join('');
}

function loadErrorDefault(status, jqXHR) {
	ajaxError(jqXHR, status);
}
